package org.jiuling.aliyun.sms.config;


import org.jiuling.aliyun.config.AliYunConfig;
import org.jiuling.aliyun.config.enums.ServiceAccessPointEnum;
import org.jiuling.aliyun.config.exception.AliYunConfigRuntimeException;
import org.jiuling.aliyun.sms.enums.PatternEnum;
import org.jiuling.basics.validation.ObjectVerify;

/**
 * 阿里云短信配置
 * @author 紫灵
 * @date 2023年01月03日 18时08分21秒
 */
public class AliYunSmsConfig {

    public AliYunSmsConfig(AliYunConfig aliYunConfig){
        this.aliYunConfig = aliYunConfig;
    }

    /** 阿里云配置 */
    private final AliYunConfig aliYunConfig;
    /** 签名 */
    private String signName;
    /** 服务点接入 */
    private ServiceAccessPointEnum serviceAccessPoint;
    /** 调用方式 */
    private PatternEnum pattern;

    public AliYunConfig getAliYunConfig() {
        return aliYunConfig;
    }

    public String getSignName() {
        return signName;
    }

    public void setSignName(String signName) {
        this.signName = signName;
    }

    public ServiceAccessPointEnum getServiceAccessPoint() {
        return serviceAccessPoint;
    }

    public void setServiceAccessPoint(ServiceAccessPointEnum serviceAccessPoint) {
        this.serviceAccessPoint = serviceAccessPoint;
    }

    public PatternEnum getPattern() {
        return pattern;
    }

    public void setPattern(PatternEnum pattern) {
        this.pattern = pattern;
    }

    /** 建造者 */
    public static class Builder{
        /** 阿里云手机配置 */
        private final AliYunSmsConfig aliYunSmsConfig;

        public Builder(AliYunConfig aliYunConfig) {
            aliYunSmsConfig = new AliYunSmsConfig(aliYunConfig);
        }

        /**
         * 添加签名
         * @param signName 签名
         * @return 建造者
         */
        public Builder addSignName(String signName){
            aliYunSmsConfig.signName = signName;
            return this;
        }

        /**
         * 添加服务接入点
         * @param serviceAccessPoint 服务接入点
         * @return 建造者
         */
        public Builder addServiceAccessPoint(ServiceAccessPointEnum serviceAccessPoint){
            aliYunSmsConfig.serviceAccessPoint = serviceAccessPoint;
            return this;
        }

        /**
         * 添加调用方式
         * @param pattern 调用方式
         * @return 当前对象
         */
        public Builder addPattern(PatternEnum pattern){
            aliYunSmsConfig.pattern = pattern;
            return this;
        }

        /**
         * 建造
         * @return 阿里云短信配置
         */
        public AliYunSmsConfig build(){
//            if(StringVerify.isBlank(aliYunSmsConfig.signName)){
//                throw new AliYunSMSRuntimeException("签名不能为空！");
//            }
            if(ObjectVerify.isNull(aliYunSmsConfig.serviceAccessPoint)){
                throw new AliYunConfigRuntimeException("服务接入点不能为空！");
            }
            return aliYunSmsConfig;
        }


    }
}
